导入相关的包¶

In [1]:
import pandas as pd
import matplotlib.pyplot as plt

一、读取上一步保存的本地csv文件¶

In [2]:
Company=pd.read_csv('company.csv',).iloc[:,1:]
company=Company.iloc[:,1].tolist()
dflist=[]
for name in company:
    com = name.replace('*','')
    data=pd.read_csv('【'+com+'】.csv')
    dflist.append(data)  #将所有的csv文件保存到一个list里方便后续调用
In [3]:
comps = len(dflist)
for i in range(comps):
    dflist[i]=dflist[i].set_index('年份')
In [4]:
dflist
Out[4]:
[                            营业收入(元)  基本每股收益(元/股)
 年份                                              
 2011                   1104104689.8       0.0680
 2012                   851295800.76       0.0170
 2013                  1719531920.81       0.0320
 2014                  1005817243.57       0.0580
 2015                   729998909.71       0.0690
 2016                   891077257.45       0.0737
 2017                  1298149934.33       0.1328
 2018                  1121254823.29       0.3376
 2019                  1164257304.12       0.0261
 2020                  2333326709.68       0.0886
 2021                  1871731105.96      -0.3671
 股票简称                            罗牛山          NaN
 股票代码                         000735          NaN
 办公地址  海南省海口市美兰区国兴大道 5 号海南大厦农信楼 10 楼          NaN
 公司网址      http://www.luoniushan.com          NaN,
                           营业收入(元)  基本每股收益(元/股)
 年份                                            
 2011                          NaN          NaN
 2012                          NaN          NaN
 2013                          NaN          NaN
 2014                          NaN          NaN
 2015                          NaN          NaN
 2016                          NaN          NaN
 2017                          NaN          NaN
 2018                          NaN          NaN
 2019                          NaN          NaN
 2020                          NaN          NaN
 2021                1051843098.16          1.3
 股票简称                         东瑞股份          NaN
 股票代码                       001201          NaN
 办公地址  广东省河源市东源县仙塘镇蝴蝶岭工业城 01-11 地块          NaN
 公司网址   http://www.gdruichang.com/          NaN,
                                 营业收入(元)  基本每股收益(元/股)
 年份                                                  
 2011                      1736446536.51         0.15
 2012                      2042040537.48         0.22
 2013                       2078401943.1         0.57
 2014                       2603349676.0         0.16
 2015                      2141293716.15         0.51
 2016                      2370462254.75         0.59
 2017                      3061060630.82         0.34
 2018                      4518950572.98        -0.49
 2019                      6006883384.85         0.09
 2020                     10764148563.64         2.68
 2021                     10506630781.93        -2.43
 股票简称                               天邦股份          NaN
 股票代码                             002124          NaN
 办公地址  江苏省南京市浦口区行知路 8 号南京国家农创园公共创新平台 B 座          NaN
 公司网址                   www.tianbang.com          NaN,
                        营业收入(元)  基本每股收益(元/股)
 年份                                         
 2011            10690093060.91       0.2800
 2012             13626735837.0       0.1900
 2013            15582493561.33      -0.0700
 2014            16483547772.92       0.0800
 2015             16416267218.4       0.5200
 2016            18920144828.29       0.5200
 2017             20614922289.5       0.2300
 2018            22112983900.32       0.0800
 2019            24517770453.37       0.6857
 2020            49166305434.56       2.2871
 2021            47670223670.25      -6.0060
 股票简称                      正邦科技          NaN
 股票代码                    002157          NaN
 办公地址  江西省南昌市高新技术开发区艾溪湖一路 569 号          NaN
 公司网址  http://www.zhengbang.com          NaN,
                     营业收入(元)  基本每股收益(元/股)
 年份                                      
 2011          1345200246.26         1.68
 2012          1191149389.46        -0.27
 2013           996313767.09        -0.81
 2014          1186417366.13         0.21
 2015           900799701.79        -1.04
 2016          1408702921.15         0.51
 2017          1067502353.94        -0.96
 2018          1817711386.36         1.26
 2019          3276052000.43         5.33
 2020          1681883981.38         0.22
 2021           1775432179.3         0.14
 股票简称                   民和股份          NaN
 股票代码                 002234          NaN
 办公地址  山东省烟台市蓬莱区南关路 2 号附 3 号          NaN
 公司网址    http://www.minhe.cn          NaN,
                       营业收入(元)  基本每股收益(元/股)
 年份                                        
 2011            3111347537.01       0.5400
 2012            4099300058.91       0.0029
 2013             4708227702.1      -0.2412
 2014            6436059894.41       0.0836
 2015            6939825279.22      -0.3714
 2016            8340420528.35       0.6110
 2017            10158794866.3       0.2562
 2018           11547228731.64       1.2146
 2019           14558436761.99       3.3019
 2020           13744599499.34       1.6431
 2021            14478196536.2       0.3619
 股票简称                     圣农发展          NaN
 股票代码                   002299          NaN
 办公地址        福建省光泽县十里铺圣农总部办公大楼          NaN
 公司网址  http://www.sunnercn.com          NaN,
                   营业收入(元)  基本每股收益(元/股)
 年份                                    
 2011        1685878719.46       0.5800
 2012        1809417147.54       0.0150
 2013         1756369219.8      -0.3540
 2014         1843102830.0       0.0295
 2015        1857499503.11       0.0410
 2016         2514708469.8       0.1710
 2017        4121925898.01       0.1147
 2018        5348828565.38       0.2230
 2019        5517686134.68      -0.0979
 2020        3125556245.34      -1.7770
 2021         3192457799.0      -4.5880
 股票简称                *ST华英          NaN
 股票代码               002321          NaN
 办公地址  河南省潢川县产业集聚区工业大道 1 号          NaN
 公司网址                  NaN          NaN,
                    营业收入(元)  基本每股收益(元/股)
 年份                                     
 2011          770378185.51         1.67
 2012          601419273.54         0.04
 2013          502875826.03        -1.03
 2014          841921368.35         0.08
 2015          604290341.75        -1.43
 2016         1611132544.74         1.70
 2017          656404863.44        -0.92
 2018         1473118954.89         1.08
 2019          3583534105.0         3.79
 2020         1751036372.39         0.09
 2021         2089921928.63         0.03
 股票简称                  益生股份          NaN
 股票代码                002458          NaN
 办公地址      山东省烟台市福山区益生路 1 号          NaN
 公司网址  www.yishenggufen.com          NaN,
                          营业收入(元)  基本每股收益(元/股)
 年份                                           
 2011                         NaN          NaN
 2012                         NaN          NaN
 2013               2044402771.09         1.43
 2014               2604763390.34         0.33
 2015               3003474722.79         1.23
 2016               5605907003.09         2.25
 2017              10042415931.26         2.12
 2018              13388157685.94         0.17
 2019              20221332525.64         2.82
 2020              56277065607.85         7.46
 2021               78889870566.4         1.28
 股票简称                        牧原股份          NaN
 股票代码                      002714          NaN
 办公地址             河南省南阳市卧龙区龙升工业园区          NaN
 公司网址  http://www.muyuanfoods.com          NaN,
                       营业收入(元)  基本每股收益(元/股)
 年份                                        
 2011                      NaN          NaN
 2012                      NaN          NaN
 2013                      NaN          NaN
 2014                      NaN          NaN
 2015                      NaN          NaN
 2016                      NaN          NaN
 2017                      NaN          NaN
 2018                      NaN          NaN
 2019                      NaN          NaN
 2020            2189585769.77         1.87
 2021            3005507323.26         0.25
 股票简称                     湘佳股份          NaN
 股票代码                   002982          NaN
 办公地址  湖南省石门县经济开发区天供山社区夹山路 9 号          NaN
 公司网址     www.xiangjiamuye.com          NaN,
                  营业收入(元)  基本每股收益(元/股)
 年份                                   
 2011        314699751.71         0.33
 2012        481038879.97         0.27
 2013        451460275.35         0.23
 2014        771379830.66         0.14
 2015        599902012.38         0.14
 2016        664584792.47        -0.26
 2017        692557176.69        -1.74
 2018        677811826.82         0.09
 2019         649011242.0        -0.27
 2020        820327472.41         0.06
 2021       1127956763.43         0.07
 股票简称                西部牧业          NaN
 股票代码              300106          NaN
 办公地址  新疆石河子市开发区北一东路 28 号          NaN
 公司网址      www.xjxbmy.com          NaN,
                  营业收入(元)  基本每股收益(元/股)
 年份                                   
 2011                 NaN          NaN
 2012         82003499.07       0.2288
 2013          82656575.6       0.1058
 2014        121943044.66       0.0197
 2015        246867894.03      -0.2000
 2016        375207065.81      -0.7200
 2017        195305726.71       0.0400
 2018        105225957.21      -7.0900
 2019        229005660.26      -0.1900
 2020        163309323.59       0.0100
 2021        107976195.34      -0.0900
 股票简称                ST天山          NaN
 股票代码              300313          NaN
 办公地址  新疆昌吉市阿什里乡天山生物育种产业园          NaN
 公司网址      www.xjtssw.com          NaN,
                 营业收入(元)  基本每股收益(元/股)
 年份                                  
 2011                NaN          NaN
 2012                NaN          NaN
 2013                NaN          NaN
 2014                NaN          NaN
 2015     48237369754.91       1.7100
 2016     59355237219.15       2.7101
 2017      55657160144.3       1.2932
 2018     57235997041.92       0.7511
 2019     73120412619.72       2.6614
 2020     74923760203.84       1.1752
 2021     64954064169.73      -2.1103
 股票简称               温氏股份          NaN
 股票代码             300498          NaN
 办公地址  云浮市新兴县新城镇东堤北路 9 号          NaN
 公司网址    www.wens.com.cn          NaN,
                         营业收入(元)  基本每股收益(元/股)
 年份                                          
 2011                        NaN          NaN
 2012                        NaN          NaN
 2013                        NaN          NaN
 2014                        NaN          NaN
 2015                        NaN          NaN
 2016                        NaN          NaN
 2017                        NaN          NaN
 2018              7214329050.45       3.5844
 2019              8870466583.29       4.9477
 2020              8620966215.37       0.6291
 2021             11131728138.55      -0.9795
 股票简称                       立华股份          NaN
 股票代码                     300761          NaN
 办公地址     常州市武进区牛塘镇卢西村委河西村 500 号          NaN
 公司网址  http://www.lihuamuye.com/          NaN,
                      营业收入(元)  基本每股收益(元/股)
 年份                                       
 2011                     NaN          NaN
 2012                     NaN          NaN
 2013                     NaN          NaN
 2014                     NaN          NaN
 2015                     NaN          NaN
 2016                     NaN          NaN
 2017                     NaN          NaN
 2018                     NaN          NaN
 2019                     NaN          NaN
 2020             540018818.0         0.36
 2021            714367715.43         0.48
 股票简称                    晓鸣股份          NaN
 股票代码                  300967          NaN
 办公地址        宁夏银川市金凤区创业街 36 号          NaN
 公司网址  http://www.nxxmqy.com/          NaN,
                        营业收入(元)  基本每股收益(元/股)
 年份                                         
 2011                       NaN          NaN
 2012             1037944248.42         0.09
 2013             1130087615.49         0.06
 2014             1302493866.31        -0.21
 2015             1326036664.34         0.13
 2016             1691374321.68         0.30
 2017             1723720756.85         0.07
 2018             2041039866.32        -0.05
 2019              2130425322.0         0.10
 2020              2723731158.0         0.43
 2021             2002862891.24        -0.41
 股票简称                       新五丰          NaN
 股票代码                    605296          NaN
 办公地址  湖南省长沙市五一西路2号“第一大道”19、20楼          NaN
 公司网址             www.newwf.com          NaN,
                   营业收入(元)  基本每股收益(元/股)
 年份                                    
 2011                  NaN          NaN
 2012                  NaN          NaN
 2013                  NaN          NaN
 2014                  NaN          NaN
 2015                  NaN          NaN
 2016                  NaN          NaN
 2017         655487654.44         0.35
 2018         618892056.81         0.25
 2019         555559032.55         0.16
 2020        1439190604.09         0.38
 2021        2982922735.67         0.53
 股票简称                 巨星农牧          NaN
 股票代码               605296          NaN
 办公地址        乐山市五通桥区竹根镇新华村          NaN
 公司网址  www.juxingnongmu.cn          NaN,
                        营业收入(元)  基本每股收益(元/股)
 年份                                         
 2011                       NaN          NaN
 2012                       NaN          NaN
 2013                       NaN          NaN
 2014                       NaN          NaN
 2015                       NaN          NaN
 2016                       NaN          NaN
 2017                       NaN          NaN
 2018                       NaN          NaN
 2019                       NaN          NaN
 2020                       NaN          NaN
 2021             2779458827.93         0.64
 股票简称                      神农集团          NaN
 股票代码                    605296          NaN
 办公地址  云南省昆明市盘龙区东风东路23号昆明恒隆广场办公          NaN
 公司网址            www.ynsnjt.com          NaN]

二、构造函数比较各公司近十年总营业收入用于绘图(为了画图美观,没有以2021年营业收入排序。因为这样可能筛选出来较多近几年上市的公司,NaN值太多绘图不好看)¶

In [5]:
def compare_rev(data):
    df=pd.DataFrame(columns=['近十年总营业收入(元)'])
    for i in range(comps):
        df.loc[dflist[i].loc['股票简称','营业收入(元)'],'近十年总营业收入(元)']=dflist[i].iloc[:11,0].astype(float).sum()
    return df
rank=compare_rev(dflist).sort_values('近十年总营业收入(元)',ascending=False).head(10) #取营业收入总量前十家的公司
rank
Out[5]:
近十年总营业收入(元)
温氏股份 433484001153.569946
正邦科技 255801488026.850006
牧原股份 192077390204.399994
圣农发展 98122437395.469986
天邦股份 47829668598.209999
立华股份 35837489987.660004
*ST华英 32773430532.119999
新五丰 17109716710.65
民和股份 16647165293.290001
益生股份 14486033764.27

为什么最多保留两位小数的浮点数相加后有的会出现6位小数?¶

浮点数0.1 + 0.2 其实不等于0.3¶

In [6]:
0.1+0.2 == 0.3
Out[6]:
False
In [7]:
a=0.1+0.2
a
Out[7]:
0.30000000000000004

感兴趣的话可以查看这篇文章:¶

https://xufive.blog.csdn.net/article/details/103816159

三、构造营业收入和每股收益的数据表用于绘图¶

In [8]:
rank.index
Out[8]:
Index(['温氏股份', '正邦科技', '牧原股份', '圣农发展', '天邦股份', '立华股份', '*ST华英', '新五丰', '民和股份',
       '益生股份'],
      dtype='object')
In [9]:
names=['温氏股份', '正邦科技', '牧原股份', '圣农发展', '天邦股份', '立华股份', '*ST华英', '民和股份', '新五丰',
       '益生股份']
In [10]:
indexes=[] #找出排名前十的公司公司名称在company列表里的索引,用于定位它在dflist里的位置
for idx in names:
    indexes.append(company.index(idx))
In [11]:
datalist=[] 
datalist1=[]
for i in indexes: #在dflist里选出所需公司的营业收入数据
        datalist.append(pd.DataFrame(dflist[i].iloc[:11,0]))
for df in datalist:
    df.index=df.index.astype(int)
    df['营业收入(元)']=df['营业收入(元)'].astype(float)/1000000000
for i in indexes: #在dflist里选出所需公司的每股收益数据
        datalist1.append(pd.DataFrame(dflist[i].iloc[:11,1]))
for df in datalist1:
    df.index=df.index.astype(int)
    df['基本每股收益(元/股)']=df['基本每股收益(元/股)'].astype(float)
In [12]:
hori_rev=pd.concat(datalist,axis=1) #将所有公司的df合并成汇总表
hori_eps=pd.concat(datalist1,axis=1)
hori_rev.columns=rank.index
hori_eps.columns=rank.index
In [13]:
hori_rev
Out[13]:
温氏股份 正邦科技 牧原股份 圣农发展 天邦股份 立华股份 *ST华英 新五丰 民和股份 益生股份
年份
2011 NaN 10.690093 NaN 3.111348 1.736447 NaN 1.685879 1.345200 NaN 0.770378
2012 NaN 13.626736 NaN 4.099300 2.042041 NaN 1.809417 1.191149 1.037944 0.601419
2013 NaN 15.582494 2.044403 4.708228 2.078402 NaN 1.756369 0.996314 1.130088 0.502876
2014 NaN 16.483548 2.604763 6.436060 2.603350 NaN 1.843103 1.186417 1.302494 0.841921
2015 48.237370 16.416267 3.003475 6.939825 2.141294 NaN 1.857500 0.900800 1.326037 0.604290
2016 59.355237 18.920145 5.605907 8.340421 2.370462 NaN 2.514708 1.408703 1.691374 1.611133
2017 55.657160 20.614922 10.042416 10.158795 3.061061 NaN 4.121926 1.067502 1.723721 0.656405
2018 57.235997 22.112984 13.388158 11.547229 4.518951 7.214329 5.348829 1.817711 2.041040 1.473119
2019 73.120413 24.517770 20.221333 14.558437 6.006883 8.870467 5.517686 3.276052 2.130425 3.583534
2020 74.923760 49.166305 56.277066 13.744599 10.764149 8.620966 3.125556 1.681884 2.723731 1.751036
2021 64.954064 47.670224 78.889871 14.478197 10.506631 11.131728 3.192458 1.775432 2.002863 2.089922
In [14]:
hori_eps
Out[14]:
温氏股份 正邦科技 牧原股份 圣农发展 天邦股份 立华股份 *ST华英 新五丰 民和股份 益生股份
年份
2011 NaN 0.2800 NaN 0.5400 0.15 NaN 0.5800 1.68 NaN 1.67
2012 NaN 0.1900 NaN 0.0029 0.22 NaN 0.0150 -0.27 0.09 0.04
2013 NaN -0.0700 1.43 -0.2412 0.57 NaN -0.3540 -0.81 0.06 -1.03
2014 NaN 0.0800 0.33 0.0836 0.16 NaN 0.0295 0.21 -0.21 0.08
2015 1.7100 0.5200 1.23 -0.3714 0.51 NaN 0.0410 -1.04 0.13 -1.43
2016 2.7101 0.5200 2.25 0.6110 0.59 NaN 0.1710 0.51 0.30 1.70
2017 1.2932 0.2300 2.12 0.2562 0.34 NaN 0.1147 -0.96 0.07 -0.92
2018 0.7511 0.0800 0.17 1.2146 -0.49 3.5844 0.2230 1.26 -0.05 1.08
2019 2.6614 0.6857 2.82 3.3019 0.09 4.9477 -0.0979 5.33 0.10 3.79
2020 1.1752 2.2871 7.46 1.6431 2.68 0.6291 -1.7770 0.22 0.43 0.09
2021 -2.1103 -6.0060 1.28 0.3619 -2.43 -0.9795 -4.5880 0.14 -0.41 0.03

四、绘制对比图¶

In [15]:
plt.rcParams['font.sans-serif']=['SimHei']
plt.figure(figsize=(16,30))
x = datalist[0].index

y_1 = hori_rev.iloc[:,0]
y_2 = hori_rev.iloc[:,1]
y_3 = hori_rev.iloc[:,2]
y_4 = hori_rev.iloc[:,3]
y_5 = hori_rev.iloc[:,4]
y_6 = hori_rev.iloc[:,5]
y_7 = hori_rev.iloc[:,6]
y_8 = hori_rev.iloc[:,7]
y_9 = hori_rev.iloc[:,8]
y_10 = hori_rev.iloc[:,9]
plt.xlim(2010,2022,1)
#plt.ylim()
plt.xticks(range(2011,2022),fontsize=18)
plt.yticks(fontsize=18)

plt.plot(x, y_1, color='#1E90FF', marker='^',markersize=10, linestyle='-', label=hori_rev.columns[0],linewidth = 2.5,alpha=0.8)
plt.plot(x, y_2, color='#2E8B57', marker='^', markersize=10,linestyle='-', label=hori_rev.columns[1],linewidth = 2.5,alpha=0.8)
plt.plot(x, y_3, color='#FF8C00', marker='^', markersize=10,linestyle='-', label=hori_rev.columns[2],linewidth = 2.5,alpha=0.8)
plt.plot(x, y_4, color='#4682B4', marker=9, markersize=9,linestyle='-', label=hori_rev.columns[3],linewidth = 2,alpha=0.8)
plt.plot(x, y_5, color='#FF6A6A', marker=9,markersize=9, linestyle='-', label=hori_rev.columns[4],linewidth = 2,alpha=0.8)
plt.plot(x, y_6, color='#9BCD9B', marker=9, markersize=9,linestyle='-', label=hori_rev.columns[5],linewidth =2,alpha=0.8)
plt.plot(x, y_7, color='#6495ED', marker='D', markersize=7,linestyle='-', label=hori_rev.columns[6],linewidth =1.5,alpha=0.8)
plt.plot(x, y_8, color='#FFB90F', marker='s', markersize=7,linestyle='-', label=hori_rev.columns[7],linewidth =1.5,alpha=0.8)
plt.plot(x, y_9, color='#8B3A3A', marker='D',markersize=7, linestyle='-', label=hori_rev.columns[8],linewidth =1.5,alpha=0.8)
plt.plot(x, y_10, color='#00CED1', marker='s', markersize=7,linestyle='-', label=hori_rev.columns[9],linewidth =1.5,alpha=0.8)

plt.legend(loc = "upper left",prop={'family':'simsun', 'size': 20})  # 显示图例
plt.grid(True)
title="营业收入随时间变化趋势图(2011-2021)"
plt.title(title,fontsize=25)


plt.ylabel("营业收入(十亿元)",fontsize=22)  # 设置Y轴标签
plt.xlabel("年份",fontsize=22,loc='left')  # 设置X轴标签

plt.savefig("rev1")#保存图片
plt.show()
In [16]:
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
plt.figure(figsize=(18,24))
x = datalist[0].index
#y = range(len(names_y))

y_1 = hori_eps.iloc[:,0]
y_2 = hori_eps.iloc[:,1]
y_3 = hori_eps.iloc[:,2]
y_4 = hori_eps.iloc[:,3]
y_5 = hori_eps.iloc[:,4]
y_6 = hori_eps.iloc[:,5]
y_7 = hori_eps.iloc[:,6]
y_8 = hori_eps.iloc[:,7]
y_9 = hori_eps.iloc[:,8]
y_10 = hori_eps.iloc[:,9]
plt.xlim(2010,2022,1)
#plt.ylim()
plt.xticks(range(2011,2022),fontsize=18)
plt.yticks(fontsize=18)

plt.plot(x, y_1, color='#1E90FF', marker='^',markersize=9, linestyle='-', label=hori_eps.columns[0],linewidth = 2,alpha=0.8)
plt.plot(x, y_2, color='#2E8B57', marker='^', markersize=9,linestyle='-', label=hori_eps.columns[1],linewidth = 2,alpha=0.8)
plt.plot(x, y_3, color='#FF8C00', marker='^', markersize=9,linestyle='-', label=hori_eps.columns[2],linewidth = 2,alpha=0.8)
plt.plot(x, y_4, color='#4682B4', marker=9, markersize=9,linestyle='-', label=hori_eps.columns[3],linewidth = 2,alpha=0.8)
plt.plot(x, y_5, color='#FF6A6A', marker=9,markersize=9, linestyle='-', label=hori_eps.columns[4],linewidth = 2,alpha=0.8)
plt.plot(x, y_6, color='#9BCD9B', marker=9, markersize=9,linestyle='-', label=hori_eps.columns[5],linewidth =2,alpha=0.8)
plt.plot(x, y_7, color='#6495ED', marker='D', markersize=9,linestyle='-', label=hori_eps.columns[6],linewidth =2,alpha=0.8)
plt.plot(x, y_8, color='#FFB90F', marker='s', markersize=9,linestyle='-', label=hori_eps.columns[7],linewidth =2,alpha=0.8)
plt.plot(x, y_9, color='#8B3A3A', marker='D',markersize=9, linestyle='-', label=hori_eps.columns[8],linewidth =2,alpha=0.8)
plt.plot(x, y_10, color='#00CED1', marker='s', markersize=9,linestyle='-', label=hori_eps.columns[9],linewidth =2,alpha=0.8)


plt.legend(loc = "upper left",prop={'family':'simsun', 'size': 20},framealpha=0.8)  # 显示图例
plt.grid(True)
title="基本每股收益随时间变化趋势图(2011-2021)"
plt.title(title,fontsize=25)
plt.ylabel("基本每股收益(元/股)",fontsize=22)  # 设置Y轴标签
plt.xlabel("年份",fontsize=22)  # 设置X轴标签

plt.savefig("eps")#保存图片
plt.show()
In [17]:
hori_revup=hori_rev.head(4)
hori_revmid=hori_rev.iloc[4:8]
hori_revdown=hori_rev.tail(3)
In [18]:
hori_epsup=hori_eps.head(4)
hori_epsmid=hori_eps.iloc[4:8]
hori_epsdown=hori_eps.tail(3)
In [19]:
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False

ax1=hori_revup.plot(kind='bar',figsize=(16,8),fontsize=18,alpha=0.7,grid=True)
ax1.legend(loc='best',prop={'family':'simsun', 'size': 14},framealpha=0.5)
ax1.set_xlabel('年份',loc='left',fontsize=18)
ax1.set_ylabel('营业收入(十亿元)',fontsize=18)
ax1.set_title('行业内横向对比营业收入(2011-2014)',fontsize=20)
ax1.figure.savefig('1')

ax2=hori_revmid.plot(kind='bar',figsize=(16 ,8),fontsize=18,alpha=0.7,grid=True)
ax2.legend(loc='best',prop={'family':'simsun', 'size': 14},framealpha=0.5)
ax2.set_xlabel('年份',loc='left',fontsize=18)
ax2.set_ylabel('营业收入(十亿元)',fontsize=18)
ax2.set_title('行业内横向对比营业收入(2015-2017)',fontsize=20)
ax2.figure.savefig('2')

ax3=hori_revdown.plot(kind='bar',figsize=(16,8),fontsize=18,alpha=0.7,grid=True)
ax3.legend(loc='best',prop={'family':'simsun', 'size': 14},framealpha=0.5)
ax3.set_xlabel('年份',loc='left',fontsize=18)
ax3.set_ylabel('营业收入(十亿元)',fontsize=18)
ax3.set_title('行业内横向对比营业收入(2018-2021)',fontsize=20)
ax3.figure.savefig('3')
In [20]:
ax1=hori_epsup.plot(kind='bar',figsize=(18,10),fontsize=18,grid=True,alpha=0.7)
ax1.legend(loc='best',prop={'family':'simsun', 'size': 14},framealpha=0.7)
ax1.set_xlabel('年份',loc='right',fontsize=18)
ax1.set_ylabel('基本每股收益(元/股)',fontsize=18)
ax1.set_title('行业内横向对比基本每股收益(2011-2014)',fontsize=20)
ax1.figure.savefig('4')

ax2=hori_epsmid.plot(kind='bar',figsize=(18,10),fontsize=18,grid=True,alpha=0.7)
ax2.set_xlabel('年份',loc='right',fontsize=18)
ax2.set_ylabel('基本每股收益(元/股)',fontsize=18)
ax2.set_title('行业内横向对比基本每股收益(2015-2017)',fontsize=20)
ax2.figure.savefig('5')

ax3=hori_epsdown.plot(kind='bar',figsize=(18,10),fontsize=18,grid=True,alpha=0.7)
ax3.legend(loc='best',prop={'family':'simsun', 'size': 14},framealpha=0.3)
ax3.set_xlabel('年份',loc='left',fontsize=18)
ax3.set_ylabel('基本每股收益(元/股)',fontsize=18)
ax3.set_title('行业内横向对比基本每股收益(2018-2021)',fontsize=20)
ax3.figure.savefig('6')
In [ ]: